/**
 * Class: MeshTest
 *
 * Purpose: 
 *
 * Created: Feb 19, 2010 @ 1:36:30 PM
 * @author Ken Scott
 */
package org.openfantasia.ps.shape;

import org.openfantasia.ps.particle.Particle;
import org.openfantasia.ui.PFrame;
import org.openfantasia.util.math.DPoint3;
import org.openfantasia.util.math.geometry.DMesh;
import org.openfantasia.util.math.geometry.DPolygon;

import java.util.List;

public class Mesh extends Shape {

	protected DMesh mesh;


	public Mesh(PFrame frame) {
		super(frame);
	}


	public Mesh(PFrame frame, DMesh mesh) {
		super(frame);
		this.mesh = mesh;
	}


	public void drawShape(Particle particle) {
		if (mesh != null) {
			DPoint3 size = getSize(particle);
			DPoint3 position = getPosition(particle);

			frame.beginShape(PFrame.POLYGON);
			List<DPolygon> polys = mesh.getPolygons();
			for (DPolygon poly : polys) {
				DPolygon p = poly.copy().scale(size);
				p.offset(position);

				List<DPoint3> vertices = p.getVertices();
				for (DPoint3 vertex : vertices) {
					frame.vertex(vertex);
				}
			}
			frame.endShape(PFrame.POLYGON);
		}
	}
}
